//*************************************************************************
// File Name: SaleItemList.cpp
// This is the implementation file for the member functions
// of Class SaleItemList
// "Group 3"
// CS 1C
// March 25, 2010
// Group Project: SuperWarehouse
// Due: March 25, 2010
// - KZ's comment
//*************************************************************************

#include "SaleItemList.h"

//  private class members
//  items

SaleItemList::SaleItemList() : items() {
}

SaleItemList::~SaleItemList() {
}

void SaleItemList::addItem(string itemName, float price, int qty) {
	// Loop through items

	int i, n;
	bool found;
	SaleItem *item;

	n = items.getNumElements();
	found = false;
	for (i = 0; i < n; i++) {
		item = items.retrieveElementAtIndex(i);
		if (item->name == itemName) {
			found = true;
			break;
		}
	}

	if (found) {
		item->totalSales += price * (float)qty;
		item->totalQty += qty;
	} else {
		item = new SaleItem();
		item->name = itemName;
		item->totalSales = price * (float)qty;
		item->totalQty = qty;
		items.push(item);
	}
}

GenericList<SaleItemList::SaleItem> *SaleItemList::getItems() {
	return &items;
}

